package com.nbjtjc.safe.api.sys;

import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.bean.Params;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.sys.SysRolePermissionMapper;
import com.nbjtjc.safe.model.sys.SysRolePermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统角色和权限的绑定
 */
@RequestMapping("/rolePer")
@RestController
@CrossOrigin(allowCredentials = "true",origins = {"*"})
public class SysRolePerController {
    @Autowired
    private SysRolePermissionMapper sysRolePermissionMapper;

    @RequestMapping(value = "/add",method = {RequestMethod.POST})
//    @RequiresPermissions("sys:rolePer:add")
    public Result<SysRolePermission> add(Params params){
        Result<SysRolePermission> result=new Result<>();
        try {
            if(params.getSysRolePermissions().size()<1){
                result.setFalse("不能为空");
                return result;
            }
            sysRolePermissionMapper.insertList(params.getSysRolePermissions());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/delete",method = {RequestMethod.POST})
//    @RequiresPermissions("sys:rolePer:delete")
    public Result<Boolean> delete(SysRolePermission sysRolePermission){
        Result<Boolean> result=new Result<>();
        try {
            if(ObjectUtil.isNull(sysRolePermission)||ObjectUtil.isNull(sysRolePermission.getId())){
                result.setFalse("不能为空");
                return result;
            }
            sysRolePermissionMapper.deleteByPrimaryKey(sysRolePermission.getId());
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse("错误信息"+e.getMessage());
        }
        return result;
    }

}
